<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>云天使</title>
    <meta name="description" content="云天使">
    <meta name="keywords" content="云天使">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style type="text/css">
    .el-main{
        position: absolute;
        top: 70px;
        bottom: 0px;
        left: 200px;
        right: 10px;
        padding: 0;
    }
    </style>
</head>
<body class="hold-transition skin-purple sidebar-mini">
    <div id="app">
        <el-container>
            <el-header  class="main-header" style="height:70px;">
                <nav class="navbar navbar-static-top" :class=''>

                    <!--<a href="#" class="logo" style="text-align:center">-->
                        <!--<span class="logo-lg"><img src="../img/logoo.png"></span>-->
                    <!--</a>-->
                    <div class="right-menu">
                        <span class="help"><i class="fa fa-exclamation-circle" aria-hidden="true"></i></span>
                        <el-dropdown class="avatar-container right-menu-item" trigger="click">
                            <div class="avatar-wrapper">
                                <img src="../img/user2-160x160.jpg" class="user-avatar">
                                <!--展示用户名-->
                                {{username}}
                            </div>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item divided>
                                    <span style="display:block;">
                                        <el-button @click="handleCreate()">修改密码</el-button>
                                    </span>
                                </el-dropdown-item>
                                <el-dropdown-item divided>
                                    <span style="display:block;">
                                        <el-button >
                                            <a href="/logout.do">&#12288;退出&#12288;</a>
                                        </el-button>
                                    </span>
                                </el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </div>
                </nav>
            </el-header>
            <el-container>
                <el-aside width="200px">
                    <el-menu>
                        <el-submenu v-for="menu in menuList" :index="menu.path">
                            <template slot="title">
                                <i class="fa" :class="menu.icon"></i>
                                {{menu.title}}
                            </template>
                            <template v-for="child in menu.children">
                                <el-menu-item :index="child.path">
                                    <a :href="child.linkUrl" target="right">{{child.title}}</a>
                                </el-menu-item>
                            </template>
                        </el-submenu>
                    </el-menu>
                </el-aside>
                <el-container>
                    <iframe name="right" class="el-main" src="usersetting.html" width="100%" height="580px" frameborder="0"></iframe>
                </el-container>
            </el-container>
        </el-container>

        <div class="add-form">
            <el-dialog title="修改密码" :visible.sync="dialogFormVisible">
                <el-form ref="updatePasswordForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="旧密码" prop="oldPassword">
                                <el-input v-model="formData.oldPassword" type="password"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="新密码" prop="newPassword1">
                                <el-input v-model="formData.newPassword1" type="password"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="确认新密码" prop="newPassword2">
                                <el-input v-model="formData.newPassword2" type="password"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible = false">取消</el-button>
                    <el-button type="primary" @click="updatePassword()">确定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    new Vue({
        el: '#app',
        data:{
            username:null,//用户名
            dialogFormVisible: false,//修改密码表单是否可见
            rules: {//校验规则
                oldPassword: [{ required: true, message: '旧密码为必填项', trigger: 'blur' }],
                newPassword1: [{ required: true, message: '新密码为必填项', trigger: 'blur' }],
                newPassword2: [{ required: true, message: '确认新密码为必填项', trigger: 'blur' }]
            },
            formData:{},//修改密码表单中数据
            menuList:[
                {
                    "path": "1",
                    "title": "工作台",
                    "icon":"fa-tty",
                    "children": [
                        {
                            "path": "/1-1",
                            "title": "员工管理",
                            "linkUrl":"usersetting.html",
                            "children":[]
                        }
                    ]
                },
                {
                    "path": "2",
                    "title": "会员管理",
                    "icon":"fa-dashboard",
                    "children": [
                        {
                            "path": "/2-1",
                            "title": "会员档案",
                            "linkUrl":"membersetting.html",
                            "children":[]
                        },
                        {
                            "path": "/2-2",
                            "title": "订单管理",
                            "linkUrl":"ordermanage.html",
                            "children":[]
                        }
                    ]
                },
                {
                    "path": "3",
                    "title": "预约管理",
                    "icon":"fa-dashboard",
                    "children": [
                        {
                            "path": "/3-1",
                            "title": "预约设置",
                            "linkUrl":"ordersetting.html",
                            "children":[]
                        },
                        {
                            "path": "/3-2",
                            "title": "套餐管理",
                            "linkUrl":"setmeal.html",
                            "children":[]
                        },
                        {
                            "path": "/3-3",
                            "title": "内容组管理",
                            "linkUrl":"checkgroup.html",
                            "children":[]
                        },
                        {
                            "path": "/3-4",
                            "title": "内容项管理",
                            "linkUrl":"checkitem.html",
                            "children":[]
                        },
                    ]
                },
                {
                    "path": "4",     //菜单项所对应的路由路径
                    "title": "统计分析",     //菜单项名称
                    "icon":"fa-heartbeat",
                    "children":[//是否有子菜单，若没有，则为[]
                        {
                            "path": "/4-1",
                            "title": "会员数量统计",
                            "linkUrl":"report_member.html",
                            "children":[]
                        },
                        {
                            "path": "/4-2",
                            "title": "套餐预约占比统计",
                            "linkUrl":"report_setmeal.html",
                            "children":[]
                        },
                        {
                            "path": "/4-3",
                            "title": "运营数据统计",
                            "linkUrl":"report_business.html",
                            "children":[]
                        }
                    ]
                }
            ]
        },
        created(){
            //发送请求获取当前登录用户的用户名
            axios.get('/user/getUsername').then((response)=>{
                this.username = response.data.data;
            });
        },
        methods: {
            // 弹出修改密码窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible = true;
            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },
            updatePassword() {
                //表单校验
                this.$refs['updatePasswordForm'].validate((valid)=>{
                    if(valid){
                        //表单校验通过，发送请求
                        axios.post("/usersetting/updatePassword",this.formData).then((response)=> {
                            //隐藏修改密码窗口
                            this.dialogFormVisible = false;
                            if(response.data.flag){
                                //修改成功，弹出成功提示信息
                                this.$message({
                                    message: response.data.message,
                                    type: 'success'
                                });
                                //更改成功，跳转到登录页面
                                window.location.href="../login.html";
                            }else{
                                //修改失败，弹出错误提示信息
                                this.$message.error(response.data.message);
                            }
                        }).finally(()=> {
                            this.dialogFormVisible=false;
                        });
                    }else{
                        //表单校验失败
                        this.$message.error("表单数据校验失败");
                        return false;
                    }
                });
            },


        }
    });
    $(function() {
            var wd = 200;
            $(".el-main").css('width', $('body').width() - wd + 'px');
    });
</script>
</html>
